package com.swiftops.common.util;

import com.swiftops.common.service.ThreadLocalUserService;
import com.swiftops.common.model.User;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;

/**
 * 认证工具
 */
public class SecurityUtil implements ApplicationContextAware {
    /**
     * 当前IOC
     */
    private static ApplicationContext applicationContext;

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        this.applicationContext = applicationContext;
    }

    public static User getPrincipal() {
        ThreadLocalUserService threadLocalUserService = applicationContext.getBean(ThreadLocalUserService.class);
        User user = threadLocalUserService.getUser();
        return user;
    }
}
